home *** CD-ROM | disk | FTP | other *** search
-
- #ifndef __TIMER_H_
- #define __TIMER_H_
- /**
- Peon - Win32 Games Programming Library
- Copyright (C) 2002-2005 Erik Yuzwa
-
- This library is free software; you can redistribute it and/or
- modify it under the terms of the GNU Library General Public
- License as published by the Free Software Foundation; either
- version 2 of the License, or (at your option) any later version.
-
- This library is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- Library General Public License for more details.
-
- You should have received a copy of the GNU Library General Public
- License along with this library; if not, write to the Free
- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-
- Erik Yuzwa
- peon AT wazooinc DOT com
- */
-
-
- #include "peonstdafx.h"
-
- namespace peon
- {
- /**
- * This object as a way to properly control animation and other effects in our
- * scene relying on the "timing" in the game. Every frame of the game, we
- * update this object with a snapshot of the current clock of the CPU in order
- * to create a delta (differential) with the last clock snapshot. This delta
- * controls the movement of the objects in our gameworld.
- *
- * To make this object more platform independent, feel free to investigate
- * using the SDL timer functions
- *
- * Note that on some newer multi-processor systems, the QPC doesn't always
- * cut the mustard. Depending upon your app, the resolution of timeGetTime()
- * might be enough for your object animation...
- *
- * It really just takes some experimentation folks..
- */
- class PEONMAIN_API Timer
- {
- protected:
- /** are we using the high performance timer?*/
- bool m_bUsingQPF;
-
- /** is the timer stopped? */
- bool m_bTimerStopped;
-
- /** LONGLONG for ticks/sec */
- LONGLONG m_llQPFTicksPerSec;
-
- LONGLONG m_llStopTime;
- LONGLONG m_llLastElapsedTime;
- LONGLONG m_llBaseTime;
-
- public:
- /**
- * Constructor
- */
- Timer();
-
- /**
- * Destructor
- */
- ~Timer();
-
- /**
- * This method resets the timer
- */
- void reset();
-
- /**
- * This method starts the timer
- */
- void start();
-
- /**
- * This method is used to stop/pause the timer
- */
- void stop();
-
- /**
- * This method is used to incrementally advance the
- * timer by 0.1 seconds
- */
- void advance();
-
- /**
- * This method returns the absolute system time
- * @return float - absolute system time
- */
- float getAbsoluteTime();
-
- /**
- * This method returns the current time
- * @return float - the current time
- */
- float getTime();
-
- /**
- * This method returns the time that has elapsed between
- * getElapsedTime
- * @return float - the time delta
- */
- float getElapsedTime();
-
- /**
- * This method just returns if our timer is active or not
- * @return bool - true if timer is stopped
- */
- bool isStopped();
-
- };
- }
-
- #endif
-